/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    long long x = LONG_LONG_MIN;
    bool isValidBST(TreeNode* root) {
        if (root == nullptr) return true;
        bool flagl = isValidBST(root->left);
        if (flagl == false) return false;
        if ((long long)(root->val) > x) x = root->val;
        else return false;
        bool flagr = isValidBST(root->right);
        return flagl && flagr;
    }
};


/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),
 * right(right) {}
 * };
 */
class Solution {
public:
    int ret, sum;
    int kthSmallest(TreeNode* root, int k) {
        ret = k;
        dfs(root);
        return sum;
    }
    void dfs(TreeNode* root) {
        if (root == nullptr)
            return;
        dfs(root->left);
        if (--ret == 0) {
            sum = root->val;
            return;
        }
        dfs(root->right);
        return;
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),
 * right(right) {}
 * };
 */
class Solution {
public:
    vector<string> v;
    vector<string> binaryTreePaths(TreeNode* root) {
        string path;
        dfs(root, path);
        return v;
    }
    void dfs(TreeNode* root, string path) {
        path += to_string(root->val);
        if (root->left == nullptr && root->right == nullptr)
        {
            v.push_back(path);
            return;
        }

        path += "-";
        path += ">";
        if (root->left) dfs(root->left, path);
        if (root->right) dfs(root->right, path);
    }
};











